package com.th.supcom.pds.deptdispensary.client.widget;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.th.supcom.pds.common.client.widget.PdsLayoutContainer;

/**
 * 新增编辑窗口
 * 
 * @author 杨冲
 */
public class PhamMeterialTypeEditWindow extends Window
{
    private DeptVsDispensaryFields m_fields;
    private DeptVsDispensaryButtons m_buttons;
    private final boolean m_isEdit;

    /**
     * 构造函数
     */
    public PhamMeterialTypeEditWindow (boolean isEdit)
    {
        m_isEdit = isEdit;
    }

    /**
     * 设置文本组件
     * 
     * @param fields
     */
    public void setFields (DeptVsDispensaryFields fields)
    {

        m_fields = fields;
    }

    /**
     * 设置按钮组件
     * 
     * @param buttons
     */
    public void setButtons (DeptVsDispensaryButtons buttons)
    {

        m_buttons = buttons;
    }

    /**
     * 初始化UI
     */
    public void initUI ()
    {
        if (m_isEdit)
        {
            setHeading ("编辑护理单元药房配置");
        }
        else
        {
            setHeading ("新增护理单元药房配置");
        }

        setPixelSize (500, 150);
        setLayout (new FitLayout ());
        setButtonAlign (HorizontalAlignment.CENTER);

        FormPanel formPanel = new FormPanel ();
        formPanel.setHeaderVisible (false);
        formPanel.setLayout (new FormLayout ());
        List <Component> firstColumn = new ArrayList <Component> ();
        firstColumn.add (m_fields.getPhamMaterialBox ());

        List <Component> secondColumn = new ArrayList <Component> ();
        secondColumn.add (m_fields.getDispensaryBox ());

        PdsLayoutContainer container = new PdsLayoutContainer ();
        container.insertWidgets (firstColumn, 1);
        container.insertWidgets (secondColumn, 1);
        container.init ();
        formPanel.add (container);
        add (formPanel);
        addButton (m_buttons.getConfirmButton ());
        if (!m_isEdit)
        {
            addButton (m_buttons.getAddContinueButton ());
        }
        addButton (m_buttons.getCancelButton ());
    }

}
